package com.zhongxi.guoyuan.OffLineShop;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.zhongxi.guoyuan.R;

import io.reactivex.disposables.Disposable;

/**
 * Created by Administrator on 2018/1/9.
 */

public class  OffLineBaseFragment extends Fragment {

    protected Disposable mDisposable;
    protected int page = 1;
    private ProgressDialog mProgressDialog;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initParams();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return  init();
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
    }

    /**
     * 获取传入该fragment的参数
     */
    protected void initParams() {

    }

    /**
     * 获取布局
     * @return
     */
    protected View init() {
        return null;
    }

    /**
     *  初始化数据
     * @param view
     */
    protected void initView(View view) {

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initNet();
        initListener();
    }

    /**
     * 联网操作
     */
    protected void initNet() {

    }

    /**
     * 设置事件
     */
    protected void initListener() {

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unsubscribe();
    }

    protected void unsubscribe() {
        if (mDisposable != null && !mDisposable.isDisposed()) {
            mDisposable.dispose();
        }
    }

    protected void showProgressDialog() {
        if (mProgressDialog == null) {
            mProgressDialog = new ProgressDialog(getActivity(),R.style.CustomProgressDialog);
        }
        mProgressDialog.setMessage("加载中....");
        mProgressDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.progressbarstyle_large));
        mProgressDialog.show();
    }

    protected void dismessProgressDialog() {
        if (mProgressDialog != null && mProgressDialog.isShowing()) {
            mProgressDialog.dismiss();
        }
    }
}
